import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import eventBus from "@/common/event-bus"

Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    meta: {
      title: "挺想租-首页"
    }
  }, {
    path: '/classify',
    name: 'classify',
    component: () => import('../views/ClassifyView.vue'),
    meta: {
      title: "挺想租-分类"
    }
  }, {
    path: '/service',
    name: 'service',
    component: () => import('../views/ServiceView.vue'),
    meta: {
      title: "挺想租-客服"
    }
  }, {
    path: '/mine',
    name: 'mine',
    component: () => import('../views/MineView.vue'),
    meta: {
      title: "挺想租-我的"
    }
  }, {
    path: '/search',
    name: 'search',
    component: () => import('../views/SearchView.vue'),
    meta: {
      title: "挺想租-搜索"
    }
  }, {
    path: '/goods',
    name: 'goods',
    component: () => import('../views/GoodsView.vue'),
    meta: {
      title: "挺想租-商品详情"
    }
  }, {
    path: '/city',
    name: 'city',
    component: () => import('../views/SelectCityView.vue'),
    meta: {
      title: "挺想租-城市选择"
    }
  }, {
    path: '/list',
    name: 'list',
    component: () => import('../views/GoodList.vue'),
    meta: {
      title: "挺想租-商品列表页"
    }
  }, {
    path: '/coupon',
    name: 'coupon',
    component: () => import('../views/CouponView.vue'),
    meta: {
      title: "挺想租-我的优惠券"
    }
  }, {
    path: '/more',
    name: 'more',
    component: () => import('../views/CouponMore.vue'),
    meta: {
      title: "挺想租-领取中心"
    }
  }, {
    path: '/order',
    name: 'order',
    component: () => import('../views/OrderView.vue'),
    meta: {
      title: "挺想租-我的订单"
    }
  }, {
    path: '/business',
    name: 'business',
    component: () => import('../views/Business.vue'),
    meta: {
      title: "挺想租-商家入驻"
    },
  }, {
    path: '/proposal',
    name: 'proposal',
    component: () => import('../views/ProposalView.vue'),
    meta: {
      title: "挺想租-投诉与建议"
    },
  }, {
    path: "/write",
    name: "write",
    component: () => import('../views/ProposalWrite.vue'),
    meta: {
      title: "挺想租-投诉与建议"
    },
  }, {
    path: '/my-proposal',
    name: 'my-proposal',
    component: () => import('../views/ProposalMy.vue'),
    meta: {
      title: "挺想租-投诉与建议"
    }
  }, {
    path: '/help',
    name: 'help',
    component: () => import('../views/HelpCenter.vue'),
    meta: {
      title: "挺想租-"
    }
  }, {
    path: '/doubts',
    name: 'doubts',
    component: () => import('../views/AnsweringDoubts.vue'),
    meta: {
      title: "挺想租-帮助中心"
    }
  }, {
    path: '/confirm-order',
    name: 'confirm-order',
    component: () => import('../views/ConfirmOrder.vue'),
    meta: {
      title: "挺想租-确认订单"
    }
  }, {
    path: '/order-detail',
    name: 'order-detail',
    component: () => import('../views/OrderDetail.vue'),
    meta: {
      title: "挺想租-租赁详情"
    }
  }, {
    path: '/real-name',
    name: 'real-name',
    component: () => import('../views/RealName.vue'),
    meta: {
      title: "挺想租-实名认证"
    }
  }, {
    path: '/agreement',
    name: 'agreement',
    component: () => import('../views/Agreement.vue'),
    meta: {
      title: "挺想租-协议及相关"
    }
  }, {
    path: "/shop",
    name: "shop",
    component: () => import('../views/ShopView.vue'),
    meta: {
      title: "挺想租-店铺"
    }
  }, {
    path: "/order-info",
    name: "order-info",
    component: () => import('../views/OrderInfo.vue'),
    meta: {
      title: "挺想租-订单详情"
    }
  }, {
    path: "/billing",
    name: "billing",
    component: () => import('../views/BillingDetails.vue'),
    meta: {
      title: "挺想租-账单详情"
    }
  }, {
    path: "/login",
    name: "login",
    component: () => import('../views/LoginView.vue'),
    meta: {
      title: "挺想租-登录"
    }
  }, {
    path: "/register",
    name: "register",
    component: () => import('../views/RegisterView.vue'),
    meta: {
      title: "挺想租-注册"
    }
  },
  {
    path: "/address",
    name: "address",
    component: () => import('../views/AddressInfo.vue'),
    meta: {
      title: "挺想租-我的地址蒲"
    }
  }, {
    path: "/add-address",
    name: "add-address",
    component: () => import('../views/AddAddress.vue'),
    meta: {
      title: "挺想租-编辑地址"
    }
  }, {
    path: '/',
    redirect: '/home'
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  eventBus.$emit("switchPage", to.path);

  if (to.meta.title) {
    document.title = to.meta.title
  } else {
    document.title = "挺想租"
  }
  next()
})
export default router
